home *** CD-ROM | disk | FTP | other *** search
- //***********************************************************************
- //
- // FontView.cpp
- //
- //***********************************************************************
-
- #include <afxwin.h>
- #include "FontView.h"
-
- #define IDC_PRINT 100
- #define IDC_CHECKBOX 101
- #define IDC_LISTBOX 102
- #define IDC_SAMPLE 103
-
- CMyApp myApp;
-
- /////////////////////////////////////////////////////////////////////////
- // CMyApp member functions
-
- BOOL CMyApp::InitInstance ()
- {
- m_pMainWnd = new CMainWindow;
- m_pMainWnd->ShowWindow (m_nCmdShow);
- m_pMainWnd->UpdateWindow ();
- return TRUE;
- }
-
- /////////////////////////////////////////////////////////////////////////
- // CMainWindow message map and member functions
-
- BEGIN_MESSAGE_MAP (CMainWindow, CWnd)
- ON_WM_CREATE ()
- ON_BN_CLICKED (IDC_PRINT, OnPushButtonClicked)
- ON_BN_CLICKED (IDC_CHECKBOX, OnCheckBoxClicked)
- ON_LBN_SELCHANGE (IDC_LISTBOX, OnSelChange)
- END_MESSAGE_MAP ()
-
- CMainWindow::CMainWindow ()
- {
- CString strWndClass = AfxRegisterWndClass (
- 0,
- myApp.LoadStandardCursor (IDC_ARROW),
- (HBRUSH) (COLOR_3DFACE + 1),
- myApp.LoadStandardIcon (IDI_APPLICATION)
- );
-
- CreateEx (0, strWndClass, "FontView",
- WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX,
- CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
- NULL, NULL, NULL);
-
- CRect rect (0, 0, m_cxChar * 68, m_cyChar * 26);
- CalcWindowRect (&rect);
-
- SetWindowPos (NULL, 0, 0, rect.Width (), rect.Height (),
- SWP_NOZORDER | SWP_NOMOVE | SWP_NOREDRAW);
- }
-
- int CMainWindow::OnCreate (LPCREATESTRUCT lpcs)
- {
- if (CWnd::OnCreate (lpcs) == -1)
- return -1;
-
- CClientDC dc (this);
- int nHeight = -((dc.GetDeviceCaps (LOGPIXELSY) * 8) / 72);
-
- m_fontMain.CreateFont (nHeight, 0, 0, 0, FW_NORMAL, 0, 0, 0,
- DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
- DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "MS Sans Serif");
-
- CFont* pOldFont = dc.SelectObject (&m_fontMain);
- TEXTMETRIC tm;
- dc.GetTextMetrics (&tm);
- m_cxChar = tm.tmAveCharWidth;
- m_cyChar = tm.tmHeight + tm.tmExternalLeading;
- dc.SelectObject (pOldFont);
-
- CRect rect (m_cxChar * 2, m_cyChar, m_cxChar * 48, m_cyChar * 2);
- m_ctlLBTitle.Create ("Typefaces", WS_CHILD | WS_VISIBLE | SS_LEFT,
- rect, this);
-
- rect.SetRect (m_cxChar * 2, m_cyChar * 2, m_cxChar * 48,
- m_cyChar * 18);
- m_ctlListBox.CreateEx (WS_EX_CLIENTEDGE, "listbox", NULL,
- WS_CHILD | WS_VISIBLE | LBS_STANDARD, rect.left, rect.top,
- rect.Width (), rect.Height (), m_hWnd, (HMENU) IDC_LISTBOX,
- NULL);
-
- rect.SetRect (m_cxChar * 2, m_cyChar * 19, m_cxChar * 48,
- m_cyChar * 20);
- m_ctlCheckBox.Create ("Show TrueType fonts only", WS_CHILD |
- WS_VISIBLE | BS_AUTOCHECKBOX, rect, this, IDC_CHECKBOX);
-
- rect.SetRect (m_cxChar * 2, m_cyChar * 21, m_cxChar * 66,
- m_cyChar * 25);
- m_ctlGroupBox.Create ("Sample", WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
- rect, this, (UINT) -1);
-
- rect.SetRect (m_cxChar * 4, m_cyChar * 22, m_cxChar * 64,
- (m_cyChar * 99) / 4);
- m_ctlSampleText.Create ("", WS_CHILD | WS_VISIBLE | SS_CENTER, rect,
- this, IDC_SAMPLE);
-
- rect.SetRect (m_cxChar * 50, m_cyChar * 2, m_cxChar * 66,
- m_cyChar * 4);
- m_ctlPushButton.Create ("Print Sample", WS_CHILD | WS_VISIBLE |
- WS_DISABLED | BS_PUSHBUTTON, rect, this, IDC_PRINT);
-
- m_ctlLBTitle.SetFont (&m_fontMain, FALSE);
- m_ctlListBox.SetFont (&m_fontMain, FALSE);
- m_ctlCheckBox.SetFont (&m_fontMain, FALSE);
- m_ctlGroupBox.SetFont (&m_fontMain, FALSE);
- m_ctlPushButton.SetFont (&m_fontMain, FALSE);
-
- FillListBox ();
- return 0;
- }
-
- void CMainWindow::PostNcDestroy ()
- {
- delete this;
- }
-
- void CMainWindow::OnPushButtonClicked ()
- {
- MessageBox ("This feature is currently unimplemented. Sorry!",
- "Error", MB_ICONINFORMATION | MB_OK);
- }
-
- void CMainWindow::OnCheckBoxClicked ()
- {
- FillListBox ();
- OnSelChange ();
- }
-
- void CMainWindow::OnSelChange ()
- {
- int nIndex = m_ctlListBox.GetCurSel ();
-
- if (nIndex == LB_ERR) {
- m_ctlPushButton.EnableWindow (FALSE);
- m_ctlSampleText.SetWindowText ("");
- }
- else {
- m_ctlPushButton.EnableWindow (TRUE);
- if ((HFONT) m_fontSample != NULL)
- m_fontSample.DeleteObject ();
-
- CString strFaceName;
- m_ctlListBox.GetText (nIndex, strFaceName);
-
- m_fontSample.CreateFont (-m_cyChar * 2, 0, 0, 0, FW_NORMAL,
- 0, 0, 0, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS,
- CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH |
- FF_DONTCARE, strFaceName);
-
- m_ctlSampleText.SetFont (&m_fontSample);
- m_ctlSampleText.SetWindowText ("AaBbCcDdEeFfGg");
- }
- }
-
- void CMainWindow::FillListBox ()
- {
- m_ctlListBox.ResetContent ();
-
- CClientDC dc (this);
- ::EnumFontFamilies ((HDC) dc, NULL, (FONTENUMPROC) EnumFontFamProc,
- (LPARAM) this);
- }
-
- int CALLBACK CMainWindow::EnumFontFamProc (ENUMLOGFONT* lpelf,
- NEWTEXTMETRIC* lpntm, int nFontType, LPARAM lParam)
- {
- CMainWindow* pWnd = (CMainWindow*) lParam;
-
- if ((pWnd->m_ctlCheckBox.GetCheck () == BST_UNCHECKED) ||
- (nFontType & TRUETYPE_FONTTYPE))
- pWnd->m_ctlListBox.AddString (lpelf->elfLogFont.lfFaceName);
-
- return 1;
- }
-